<?php
session_start();
require_once("../models/Unit.php");
class ViewFinancialInformationController{
	var $requests;
	function getFinancialForm($unit_name){
		$unit = new Unit;
		$unit->connect();
		$details = $unit->getFinancialInformation($unit_name);
		?>
		<form id="editfinancialinfoform5">
		Deposit: P<input type="text" id="deposit" name="deposit" value="<?php echo $details['deposit']; ?>" /><br />
		Total Debts Before Automation: <br />P<input type="text" id="debts" name="debts" value="<?php echo $details['previous_debts']; ?>" /><br />
		<input type="submit" value="Update" onclick="if($('#editfinancialinfoform5').valid()){updateFinancialInfo()}" />
		</form>
		<?php
	}
	
	function getFinancialInfo($unit_name){
		$unit = new Unit;
		$unit->connect();
		$details = $unit->getFinancialInformation($unit_name);
		?>
	

		Deposit: P<?php echo $details['deposit']; ?><br />
		Total Debts Before Automation: P<?php echo $details['previous_debts']; ?><br />
		<?php if(($_SESSION['username'])=="admin"){?>
		<input type="button" value="Edit" onclick="viewFinancialForm()" />
		<?php
		}
	}
	
	function requestRequest($id){
		$request = new Request;
		$request->connect();
		$requestMessage = $request->getRequest($id);
		echo $requestMessage['message'];
	}

}

	$a = new ViewFinancialInformationController;
	$unit = new Unit;
	$unit->connect();
		if(!$unit->isOccupied($_REQUEST['unit_name'])){
		//echo "Unit is not occupied.";
		die;
	}
	if($_REQUEST['mode']==1)
		$a->getFinancialForm($_REQUEST['unit_name']);
	else
		$a->getFinancialInfo($_REQUEST['unit_name']);
	
?>